package com.demo.deal_service;

import com.demo.deal_service.dao.DealDao;
import com.demo.deal_service.model.entity.Deal;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.Random;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class InsertTestDataUtil {
    @Autowired
    DealDao dealDao;

    /**
     * 输入对应的数值，向表插入对应数量的记录
     */
    @Test
    public void insertData() {
        int insertNum = 1;
        while (insertNum-- > 0) {
            dealDao.insertDeal(genRandomDeal());
        }
    }

    public static Deal genRandomDeal() {
        Deal ret = new Deal();
        Random random = new Random(System.currentTimeMillis());
        Double randomDouble = random.nextDouble();
        int randomInt = random.nextInt(100) + 1;
        int[] randomInts = random.ints(2,10,100).toArray();
        Long nowtime = new Date().getTime();
        Date pDate = new Date(nowtime + randomInts[0]*864000L);
        Date sDate = new Date(nowtime + randomInts[1]*864000L);
        Date eDate = new Date(nowtime + randomInts[1]*864000L + 864000L);

        ret.setCategory("Category" + randomInt);
        ret.setCreateTime(new Date());
        ret.setUpdateTime(new Date());
        ret.setEndTime(eDate);
        ret.setStartTime(sDate);
        ret.setPublishTime(pDate);
        ret.setDealPrice(randomDouble);
        ret.setDealTitle("Title" + randomInt);
        ret.setDealType(1);
        ret.setDiscount(1);
        ret.setPublishStatus(1);
        ret.setImageUrl("");
        ret.setRemark("remark" + randomInt);
        ret.setInventoryAmount(1);
        ret.setVendibilityAmount(1);
        ret.setMerchantAddress("merchantAddress" + randomInt);
        ret.setMerchantName("merchantName" + randomInt);

        return ret;
    }
}
